//
//  DownLoadImageCollectionViewCell.m
//  WuliHanhan
//
//  Created by tang on 16/3/9.
//  Copyright © 2016年 LVpeng. All rights reserved.
//

#import "DownLoadImageCollectionViewCell.h"


@interface DownLoadImageCollectionViewCell ()
{
    UIImageView *photoImageView;
    UIButton *selectButton;
    UIImageView *selectImage;
    
}
@end


@implementation DownLoadImageCollectionViewCell



- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initUI];
    }
    return self;
}


- (void)initUI
{
    [self setBackgroundColor:[UIColor yellowColor]];
    photoImageView = [[UIImageView alloc] initWithFrame:self.bounds];
    [self addSubview:photoImageView];
    
    UIImage *image = [UIImage imageNamed:@"weixuanze.png"];
    
    selectImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.bounds.size.width-3-image.size.width, self.bounds.size.height-3-image.size.height, image.size.width, image.size.height)];
    [selectImage setUserInteractionEnabled:YES];
    [self addSubview:selectImage];
    
    
    selectButton = [[UIButton alloc] initWithFrame:self.bounds];
    [self addSubview:selectButton];
    [selectButton addTarget:self action:@selector(selectImage:)forControlEvents:UIControlEventTouchUpInside];
    
}


//- (void)setTag:(NSInteger)tag
//{
//    [selectButton setTag:tag];
//}



//设置图片
- (void)setDataImage:(UIImage *)dataImage
{
    [photoImageView setImage:dataImage];
}



//选择图片
- (void)selectImage:(UIButton *)sender
{
    if ([selectButton isSelected])
    {
        //取消选中
        [selectImage setImage:[UIImage imageNamed:@"weixuanze.png"]];
        
        [selectButton setSelected:NO];
    }
    else
    {
        //选中图片
        [selectImage setImage:[UIImage imageNamed:@"Arrow.png"]];
        
        [selectButton setSelected:YES];
    }
    
    if (_MDownLoadImageCollectionViewCellDelegate && [_MDownLoadImageCollectionViewCellDelegate respondsToSelector:@selector(chooseImageWithIndex:withSelectBool:)])
    {
        [_MDownLoadImageCollectionViewCellDelegate chooseImageWithIndex:self.tag withSelectBool:[selectButton isSelected]];
    }

}




//加载数据
- (void)setModelWith:(NSArray *)array
{
//    NSLog(@"%@", array);
//    NSLog(@"%d", self.tag);
    
    if ([array containsObject:[NSString stringWithFormat:@"%d", (int)self.tag]])
    {
        [selectImage setImage:[UIImage imageNamed:@"Arrow.png"]];
        [selectButton setSelected:YES];
        
    }
    else
    {
        [selectImage setImage:[UIImage imageNamed:@"weixuanze.png"]];
        [selectButton setSelected:NO];
        
    }
    
}



@end
